package com.jrx.anytxn.common.exception;


import com.jrx.anytxn.common.data.TxnRespCode;

/**
 * 自定的异常类  默认对http code 500
 *
 * @author zhaowg
 * @date 2018-07-19
 */
public class TxnException extends  Exception{

	private static final long serialVersionUID = 71134982560437988L;

    /***
     * 业务错误码
     */
	private int errCode = 9999;
    /**
     * 错误描述
     */
	private String errMsg = "default error";
	
	public TxnException(){
		super();
	}
	
	public TxnException(int errCode){
		super("errCode:"+errCode);
		this.errCode = errCode;
	}
	
	public TxnException(String errMsg){
		super(errMsg);
		this.errMsg = errMsg;
	}
	
	public TxnException(int errCode, String errMsg){
		super(errMsg);
		this.errCode = errCode;
		this.errMsg = errMsg;
	}
	
	public TxnException(Throwable cause){
		super(cause);
		if(cause!=null){
			this.errMsg = cause.getMessage();
		}
	}
	
	public TxnException(int errCode, Throwable cause){
		super(cause);
		this.errCode = errCode;
		if(cause!=null){
			this.errMsg = cause.getMessage();
		}
	}

	public TxnException(TxnRespCode code){
		super(code.getMsg());
		this.errCode = code.getCode();
		this.errMsg = code.getMsg();
	}

	public TxnException(TxnRespCode code, String msg){
		super(code.getMsg());
		this.errCode = code.getCode();
		this.errMsg =  msg!=null?msg:code.getMsg();
	}


	public int getErrCode() {
		return errCode;
	}

	public void setErrCode(int errCode) {
		this.errCode = errCode;
	}

	public String getErrMsg() {
		return errMsg;
	}

	public void setErrMsg(String errMsg) {
		this.errMsg = errMsg;
	}

	@Override
	public String toString() {
        String builder = "{\"errCode\"=\"" +
                errCode +
                "\", \"errMsg\"=\"" +
                errMsg +
                "\"}";
        return builder;
	}

	
}
